package manager;

import entity.Class;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class ClassManager implements IManager<Class> {
    private ArrayList<Class> classList;

    public ClassManager() {
        this.classList = new ArrayList<Class>();
    }
    
    @Override
    public boolean add(Class obj) {
        return this.classList.add(obj);
    }
    
    @Override
    public boolean remove(Class obj) {
        return this.classList.remove(obj);
    }
    
    @Override
    public int size() {
        return this.classList.size();
    }
    
    @Override
    public Class get(int index) {
        return this.classList.get(index);
    }
    
    @Override
    public Class replace(int index, Class obj) {
        return this.classList.set(index, obj);
    }
    
    @Override
    public Class getById(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Class getById(String id) {
        for(Class objClass: this.classList) {
            if(id.equals(objClass.getClassID())) return objClass;
        }
        return null;
    }

    @Override
    public Class getByName(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    @Override
    public void setVisible(Class obj, boolean value) {
        for(Class objClass: this.classList) {
            if(obj.getClassID().equals(objClass.getClassID())) objClass.setStatus(value);
            break;
        }
    }
    
    public Class getByVisible(int index) {
        int count = 0;
        Class obj = null;
        for(int i = 0; i < this.classList.size(); i++) {
            if(this.classList.get(i).isStatus()) 
                if(count++ == index) obj = this.classList.get(i);
        }
        return obj;
    }
    
    public Class contains(Class obj) {
        for(Class object: this.classList) {
            if(object.getClassID().equals(obj.getClassID())) return object;
        }
        return null;
    }
    
}
